package com.hejing.Lambda表达式;

import org.junit.Test;

import java.util.Comparator;

/**
 * ClassName: LambdaTest
 * Package: com.hejing.Lambda表达式
 * Description:
 *
 * @Author: HeJing
 * @Create: 2023-06-05 10:22
 * @Version: 1.0
 */
public class LambdaTest {
    @Test
    public void test01(){
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("我爱Java");
            }
        };
        r1.run();

        System.out.println("*****************************");
        // Lambda表达式的写法:
        Runnable r2 = () -> {
            System.out.println("我爱Lambda-Java");
        };
        r2.run();

    }

    @Test
    public void test02(){
        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2);
            }
        };
        int compare1 = com1.compare(12, 21);
        System.out.println(compare1);

        System.out.println("******************************");
        // Lambda表达式的写法
        Comparator<Integer> com2 = (o1, o2) -> Integer.compare(o1, o2);
        int compare2 = com2.compare(123, 32);
        System.out.println(compare2);

        System.out.println("*****************************");
        // 方法引用:
        Comparator<Integer> com3 = Integer::compare;
        int compare3 = com3.compare(32, 23);
        System.out.println(compare3);
    }


}




























